package com.funcourse.demo.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModelProperty;
import java.util.List;
import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.index.TextIndexed;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.util.StringUtils;

@Data
@Document
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Quiz {

  @ApiModelProperty("题组中的题目")
  List<Question> questions;
  @ApiModelProperty("题组封面,废弃字段")
  @JsonIgnore
  String coverUrl;
  @ApiModelProperty("题组封面")
  Image image;
  @ApiModelProperty("题组描述")
  @TextIndexed
  String description;
  @ApiModelProperty("题组名称")
  String name;
  @ApiModelProperty("题组标签")
  String tag ="其他";
  @ApiModelProperty("是否私有")
  Boolean isPrivate;
  @ApiModelProperty("不用填")
  @Indexed
  String ownerId;
  @ApiModelProperty("不用填")
  @Id
  String id;
  @Indexed
  Long createdTime;
  Long modifyTime;

  @ApiModelProperty("不用填")
  Integer testedCount=0;

  //兼容 coverUrl
  public Image getImage(){
    if(null == image){
      this.image = new Image(coverUrl,coverUrl);
    }
    return image;
  }

  public String getCoverUrl(){
    return null;
  }

}
